1
2
3
4
5 import java.io.*;
6 import java.util.*;
7
8 public class matrix {
9 static int SIZE = 30;
10
11 public static void main(String args[]) {
12 int n = Integer.parseInt(args[0]);
13 int m1[][] = mkmatrix(SIZE, SIZE);
14 int m2[][] = mkmatrix(SIZE, SIZE);
15 int mm[][] = new int[SIZE][SIZE];
16 for (int i=0; i<n; i++) {
17 mmult(SIZE, SIZE, m1, m2, mm);
18 }
19 System.out.print(mm[0][0]);
20 System.out.print(" ");
21 System.out.print(mm[2][3]);
22 System.out.print(" ");
23 System.out.print(mm[3][2]);
24 System.out.print(" ");
25 System.out.println(mm[4][4]);
26 }
27
28 public static int[][] mkmatrix (int rows, int cols) {
29 int count = 1;
30 int m[][] = new int[rows][cols];
31 for (int i=0; i<rows; i++) {
32 for (int j=0; j<cols; j++) {
33 m[i][j] = count++;
34 }
35 }
36 return(m);
37 }
38
39 public static void mmult (int rows, int cols,
40 int[][] m1, int[][] m2, int[][] m3) {
41 for (int i=0; i<rows; i++) {
42 for (int j=0; j<cols; j++) {
43 int val = 0;
44 for (int k=0; k<cols; k++) {
45 val += m1[i][k] * m2[k][j];
46 }
47 m3[i][j] = val;
48 }
49 }
50 }
51 }